#ifndef POKEMON_H
#define POKEMON_H

#include <QList>
#include <QObject>
#include <QPixmap>
#include <QString>

#include <QTimer>

// 元素类型
enum class Element {
    None = 0,     //空
    Water = 1,    //水
    Grass = 2,    //草
    Fire = 3,     //火
    Steel = 4,    //刚
    Rock = 5,     //岩石
    Electric = 6, //电
    Ice = 7,      // 冰
    Poison = 8    // 毒
};

//技能类型
enum class SkillType {
    Damage = 0, // 伤害型技能
    Heal = 1,   // 回复型技能
};

// 前向声明
class Pokemon;

// 元素相克计算
float getElementEffectiveness(Element attacker, Element defender);

// 技能基类
class Skill : public QObject
{
    Q_OBJECT
public:
    Skill(QString name, int power, Element element, QString soundPath = "", SkillType type = SkillType::Damage);

    QString getName() const { return m_name; }
    int getPower() const { return m_power; }
    Element getElement() const { return m_element; }

    void setSoundPath(const QString& path) { soundPath = path; }
    QString getSoundPath() const { return soundPath; }

    virtual int calculateDamage(Pokemon *user, Pokemon *target);
    virtual void use(Pokemon *user, Pokemon *target);

    SkillType getSkillType() const { return m_type; }

signals:
    void skillUsed(QString message);

protected:
    QString m_name;
    int m_power;
    Element m_element;
    SkillType m_type;
    QString soundPath;

};

//技能派生类--回复技能
class HealSkill : public Skill
{
public:
    // 新增两个可选参数：是否基于攻击力加成，是否基于最大HP百分比
    HealSkill(QString name,
              int basePower,
              bool scalesWithAttack = false,
              bool scalesWithMaxHP = false,
              float hpPercentage = 0.0f);

    int calculateDamage(Pokemon *user, Pokemon * /*target*/) override;

private:
    bool m_scalesWithAttack; // 是否随攻击力提升
    bool m_scalesWithMaxHP;  // 是否基于最大HP百分比
    float m_hpPercentage;    // HP百分比系数
};

// 具体技能声明

// 宝可梦类
class Pokemon : public QObject
{
    Q_OBJECT
public:
    Pokemon(QString name, int hp, int attack, int defense, Element element, QString imagePath);

    // 属性访问
    QString getName() const { return m_name; }
    int getHP() const { return m_hp; }
    int getMaxHP() const { return m_maxHP; }
    int getattack() const { return m_attack; }
    int getdefense() const { return m_defense; }
    Element getElement() const { return m_element; }
    QPixmap getImage() const { return m_image; }
    bool isAlive() const { return m_hp > 0; }

    // 技能管理
    void addSkill(Skill *skill);
    QList<Skill *> getSkills() const { return m_skills; }

    // 战斗方法
    void takeDamage(int damage); //伤害
    void heal(int amount);       //回复
    void useSkill(int index, Pokemon *target);

signals:
    void hpChanged(int currentHP, int maxHP);
    void fainted();
    void healed(int amount);
    void skillused(int index, Pokemon *user);

private:
    QString m_name;
    int m_hp, m_maxHP, m_attack, m_defense;
    Element m_element;
    QPixmap m_image;
    QList<Skill *> m_skills;
};

#endif // POKEMON_H
